package com.zjf.carpark.utils;

import org.springframework.stereotype.Component;

@Component
public class Page {
    private int limit = 10;//每页的记录数
    private int page;//当前页码
    private int totalPage;//总页数
    private int totalCount;//总记录数
    private int pageIndex;//起始页数

    public int getPageIndex() {
        return (page - 1) * limit;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getTotalPage() {
        if (totalCount % limit == 0) {
            totalPage = totalCount / limit;
        } else {
            totalPage = totalCount / limit + 1;
        }
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    @Override
    public String toString() {
        return "Page{" +
                "limit=" + limit +
                ", page=" + page +
                ", totalPage=" + totalPage +
                ", totalCount=" + totalCount +
                ", pageIndex=" + pageIndex +
                '}';
    }
}
